package com.bristua.mall.wx.controller;

import com.bristua.mall.common.bean.Result;
import com.bristua.mall.common.enums.CommonCode;
import com.bristua.mall.common.utils.HandleResultUtil;
import com.bristua.mall.common.utils.JsonUtil;
import com.bristua.mall.wx.biz.AppGetTokenBiz;
import com.bristua.mall.wx.biz.WxAppPayBiz;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/17.
 */

@RestController
@Api(value="微信用户登录",tags={"微信用户登录"})
public class AppWxLoginController {
    private static final Logger logger = LoggerFactory.getLogger(AppWxLoginController.class);
    @Autowired
    private AppGetTokenBiz appGetTokenBiz;
    @ApiOperation(value="微信用户登录")
    @PostMapping(value="/wx/app/login/{code}")
    public Result appGetOpenId(@PathVariable(value="code") String code){
        Result result = new Result();
        Map map = new HashMap<>();
        map.put("token",appGetTokenBiz.appGetToken(code,null));
        result.setData(map);
        result.setMsg(CommonCode.LOGIN_SUCCESS.getMsg());
        result.setCode(CommonCode.LOGIN_SUCCESS.getCode());
        logger.info("==>登录结果:"+ JsonUtil.toJson(result));
        return result;
    }

}
